
package com.be.beadmin.project.repository;

import com.be.beadmin.project.entity.MasterPlan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
* @author zjm
* @date 2023-01-12
**/
public interface MasterPlanRepository extends JpaRepository<MasterPlan, String>, JpaSpecificationExecutor<MasterPlan> {

    MasterPlan findMasterPlanByIdAndDelete(String id, Integer delete);

    MasterPlan findMasterPlanById(String id);


    MasterPlan findMasterPlanByInfoIdAndDelete(String infoId, Integer delete);

    @Modifying
    @Transactional
    @Query(value = "update t_pm_master_plan mp set mp.is_delete = ?1 where mp.info_id = ?2 and mp.is_delete = ?3",nativeQuery = true)
    void deleteMasterPlanByInfoIdAndDelete(int deleted,String infoId,int nodelete);

    @Modifying
    @Transactional
    @Query(value = "update t_pm_master_plan mp set mp.batch_count = ?1 where mp.id = ?2 and mp.is_delete = ?3",nativeQuery = true)
    void updateBatchPlanCountByIdAndDelete(int count,String masterPlanId,int delete);

}